﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Road3App.Model.CrossroadNs;
using Road3App.Views.UserControls.EditControls.Crossroad;

namespace Road3App.ViewModels
{
    public class EditCrossRoadCellStatesViewModel : ViewModelBase
    {
        private CrossRoad _cr;

        private CrossroadViewModel _crvm;
        public CrossroadViewModel CrossroadVM
        {
            get { return _crvm; }
            set { _crvm = value; RaisePropertyChanged("CrossroadVM"); }
        }

        private Cell _CellNoneState;
        public Cell CellNoneState
        {
            get { return _CellNoneState; }
            set { _CellNoneState = value; RaisePropertyChanged("CellNoneState"); }
        }

        private Cell _CellStartState;
        public Cell CellStartState
        {
            get { return _CellStartState; }
            set { _CellStartState = value; RaisePropertyChanged("CellStartState"); }
        }

        private Cell _CellFinishState;
        public Cell CellFinishState
        {
            get { return _CellFinishState; }
            set { _CellFinishState = value; RaisePropertyChanged("CellFinishState"); }
        }

        private Cell _CellInaccessibleState;
        public Cell CellInaccessibleState
        {
            get { return _CellInaccessibleState; }
            set { _CellInaccessibleState = value; RaisePropertyChanged("CellInaccessibleState"); }
        }

        public EditCrossRoadCellStatesViewModel(CrossRoad cr)
        {
            _cr = cr;
            CrossroadVM = new CrossroadViewModel(_cr, "cell");

            CellNoneState = new Cell() { State = CellStates.None };
            CellStartState = new Cell() { State = CellStates.Start };
            CellFinishState = new Cell() { State = CellStates.Finish };
            CellInaccessibleState = new Cell() { State = CellStates.Inaccessible };

            CrossroadVM.CellCollection.ToList().ForEach(c => c.MouseLeftButtonDown += c_MouseLeftButtonDown);
        }

        void c_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            CellUC celluc = sender as CellUC;
            Cell cell = celluc.DataContext as Cell;
            if (cell == null)
                return;

            Cell.SwitchState(cell);
        }
    }
}
